<template>
	<div class="port-page">
		<!-- 顶部按钮 -->
		<el-tabs v-model="activeName" style="margin-top: 30px;" type="card" @tab-click='tabchk'>
			<el-tab-pane label="收入总趋势图" name="zongqushi"></el-tab-pane>
			<el-tab-pane label="营业统计" name="yingye"></el-tab-pane>
			<el-tab-pane label="课销统计" name="kexiao"></el-tab-pane>
		</el-tabs>
		<div class="but1">
			<router-link to="/home">
				<el-button type="warning" size="small" class="add btn" style='margin-right: 10px;' icon="el-icon-menu">首页</el-button>
			</router-link>
			<el-date-picker  v-model="btime" type="date" style="line-height: 40px; width: 150px;"   placeholder="选择开始日期"  value-format="yyyy-MM-dd">
			</el-date-picker>
			<el-date-picker  v-model="etime" type="date" style="line-height: 40px; width: 150px;"   placeholder="选择结束日期"  value-format="yyyy-MM-dd">
			</el-date-picker>
			 <el-button  icon="el-icon-search" v-if="sjshow" type="primary" round size="small" style="margin-left: 20px;" @click="search('zje')"></el-button>
			 <el-button  icon="el-icon-search" v-if="sjshow1" type="primary" round size="small" style="margin-left: 20px;" @click="search('wpje')"></el-button>
			 <el-button  icon="el-icon-search" v-if="sjshow2" type="primary" round size="small" style="margin-left: 20px;" @click="search('kxje')"></el-button>
		</div>
		<!-- 模糊搜索条件 -->
		<!--<div style="width: 100%;text-align: center;font-size: 30px;float: left;margin-top: 20%;color: red;">-->
			<div id="srtj" style="width: 100%;height: 400px;margin-top: 50px;"></div>
		<!--</div>-->
		<LoadingComponent v-show="isLoading"></LoadingComponent>
		<router-view class="port-view"></router-view>
	</div>
</template>
<script>
	import { mapState } from 'vuex'
	import LoadingComponent from 'components/loading'
	import echarts from 'echarts'
	import qs from 'qs'
	export default {
		props: ['params'],
		components: {
			LoadingComponent,
		},
		data() {
			return {
				title:['物品金额','课程金额','预存金额'],
				title1:['总金额'],
				sjshow:true,
				sjshow1:false,
				sjshow2:false,
				btime:'',
				etime:'',
				activeName:'zongqushi',
				multipleDelNum: '', //获取批量选择的数据
				dataList: [], //表格数据
				comboxlist: [], //下拉框 动态的
				/*动画加载*/
				isLoading: true, //动画加载
				searchLoading: false, //搜索按钮触发按钮动画
				/*分页属性设置*/
				layout: 'total, sizes, prev, pager, next, jumper', //组件布局
				pageindex: this.$store.state.pageindex, //当前分页页码
				pagesizes: this.$store.state.pagesizes, //显示个数的选择器选项
				pagesize: this.$store.state.pagesize, //每页显示条目数
				total: 0, //总条数

				/*组件区域*/

				/*
				    prop :  接口参数名
				    label : 接口中文名
				    hide : 是否隐藏这一列
				    align : 这一列对齐顺序 ： left,right,center
				    headerAlign : 这一列表头对齐方式 ： left,right,center
				*/

			}
		},
		created() {
			var logininfo = JSON.parse(localStorage.logininfo);
			//加载页面时调用
			this.$store.dispatch('changeTitle', '收入统计'); //修改title
			this.$store.dispatch('changeRouterIndex', '/statistics/srtj'); //修改路由
			 var nowDate = new Date();
			 var year = nowDate.getFullYear();
			 var month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1) : nowDate.getMonth() + 1;
			 var day = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate.getDate();
			 var dateStr = year + "-" + month + "-" + day;
			 var dateStr1 = year + "-" + month + "-" + '01';
			 this.btime = dateStr1
			 this.etime = dateStr
			this.search('zje',this.title1); //分页获取默认数据
			this.isLoading = true; //动画开始
		},
		mounted() {
			//加载完成之后event
			this.isLoading = false; //动画结束
		},
		methods: {
			tabchk(tab) {
				if(tab.name == 'zongqushi') {
					this.sjshow=true,
					this.sjshow1=false,
					this.sjshow2=false,
					this.search('zje',this.title1)
				} else if(tab.name == 'yingye') {
					this.sjshow=false,
					this.sjshow1=true,
					this.sjshow2=false,
					this.search('wpje',this.title)
				} else if(tab.name == 'kexiao') {
					this.sjshow=false,
					this.sjshow1=false,
					this.sjshow2=true,
					this.search('kxje',this.title1)
				}

			},
			drawPie2(id, lststr) {
				this.charts = echarts.init(document.getElementById(id))
				this.charts.setOption({
					title: {
						text: '收入统计',
					},
					tooltip: {
						trigger: 'axis',
//						 formatter: "{b} <br/> 金额 : {c}"
					},
					legend: {
						 data:lststr
					},
					grid: {
						left: '3%',
						right: '4%',
						bottom: '3%',
						containLabel: true
					},
					toolbox: {
						feature: {
							saveAsImage: {}
						}
					},
					xAxis: {
						type: 'category',
						boundaryGap: false,
						data: this.sj
					},
					yAxis: [{
						
							type: 'value',
							name: '金额',
//							min: 0,
//							max: 100,
							position: 'left',
							
							axisLabel: {
								formatter: '{value}'
							}
						
					}],
					series: [
						{
							name: '总金额',
							type: 'line',
							data: this.zje
						},
						{
							name: '物品金额',
							type: 'line',
							data: this.wpje
						},
						
						{
							name: '课程金额',
							type: 'line',
							data:this.kcje
						},
						{
							name: '预存金额',
							type: 'line',
							data:this.ycje
						},
//						{
//							name: '直接访问',
//							type: 'line',
//							data: [320, 332, 301, 334, 390, 330, 320]
//						},
//						{
//							name: '搜索引擎',
//							type: 'line',
//							data: [820, 932, 901, 934, 1290, 1330, 1320]
//						}
					]
				})
			},
			search(id,tt) {
				//查询搜索触发事件
				this.sj = ''
				this.zje =''
				this.wpje = ''
				this.kcje = ''
//				this.spje = ''
				this.ycje = ''
				var logininfo = JSON.parse(localStorage.logininfo);
				var params3 = qs.stringify({
					day:1,
					code:id,
					lsid:'',
					bjtime:this.btime,
					edtime:this.etime,
					yhid: logininfo.id,
					xxid: logininfo.xxid,
				});
				this.searchLoading = true;
				this.axios.post(this.$store.state.api + 'ls/getlstj', params3)
					.then(res => {
						console.log(res,999988887777)
						if(id == 'zje'){
							var list = res.data.data
							var sj = list.sj.substr(0,list.sj.length-1)
							this.sj = sj.split(",");
							var zje = list.zje.substr(0,list.zje.length-1)
							this.zje = zje.split(",");
						}else if(id == 'kxje'){
							var list = res.data.data
							var sj = list.sj.substr(0,list.sj.length-1)
							this.sj = sj.split(",");
							var kxje = list.kxje.substr(0,list.kxje.length-1)
							this.zje = kxje.split(",");
						}else if(id == 'wpje'){
							var list = res.data.data
							var sj = list.sj.substr(0,list.sj.length-1)
							this.sj = sj.split(",");
							this.zje = ''
//							var jcje = list.jcje
							var kcje = list.kcje
							var wpje = list.wpje
							var ycje = list.ycje
							this.wpje = wpje.split(",");
							this.kcje = kcje.split(",");
//							this.spje = wpje.split(",");
							this.ycje = ycje.split(",");
						}
						this.$nextTick(function() {
							this.drawPie2('srtj',tt)
						});
						this.searchLoading = false;
					}).catch(res => {
						console.log(res)
						this.searchLoading = false;
					})
			},
			
			
			/* 组件的弹框  */
			componentsShow(type, data) { //显示组件
				for(let i in this.portComponents) {
					if(type == this.portComponents[i].type) {
						this.portComponents[i].toggle = true;
						this.portComponents[i].params = data;
						if(this.portComponents[i].data.type == 'single') {
							this.portComponents[i].data.index = data.row.id
						} else if(this.portComponents[i].data.type == 'multiple') {
							this.portComponents[i].data.index = this.multipleDelNum;
						} else {
							return;
						}
						return;
					}
				}
			},
			componentsHide(setting) { //关闭组件
				for(let i in this.portComponents) {
					if(setting.type == this.portComponents[i].type) {
						this.portComponents[i].toggle = false;
						if(!setting.cancel) {
							this.search();
						}
						return;
					}
				}
			}
		},
		computed: {
			...mapState([
				'api' //域名
			]),
			multipleDeleteDisabled() {
				// console.log(this.multipleDelNum)
				if(this.multipleDelNum) {
					return false;
				} else {
					return true
				}
			}
		}
	}
</script>

<style lang="less" scoped>
	.port-page {
		font-size: 12px;
		.btn {
			height: 30px;
			padding: 0 10px;
		}
		.code-search {
			height: 30px;
			margin: 10px 0 10px 0;
			min-width: 100px;
			max-width: 135px;
		}
		.class-page {
			text-align: left;
			margin-top: 10px;
		}
		.search-item {
			display: inline-block;
			margin-right: 10px;
		}
		.but1 {
			width: 100%;
			float: left;
		}
		.search {
			width: 77%;
			float: right;
			text-align: right;
		}
		.el-button+.el-button {
			margin-left: 0px;
			margin-top: 8px;
		}
	}
</style>